import React, { PureComponent } from 'react';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import { Card, Popconfirm, Switch, message, Upload, Icon, Dropdown, Menu, Divider, Drawer, Button, Form, Input, Badge, Modal, Table, Descriptions } from 'antd';
import { BaseForm, PromotionChannelsForm } from '@/components/FormTools';
import { getAllCity, getCityByPage } from '@/services/auth';
import { secMap } from '@/configs/api.map';
import { StandardTable, SearchForm } from '@joy/joy-pro';
import { getValue, to } from '@/utils/smallTool';
import { connect } from 'dva';
import moment from 'moment';
import authUtil from '@/utils/auth';
import styles from './index.less';
const pageInfo = { showSizeChanger: true, showQuickJumper: true, defaultPageSize: 10 };
const drawerConfig = {
  edit: {
    title: '编辑',
  },
  add: {
    title: '新增',
  },
};
const dateFormat = 'YYYY-MM-DD' || undefined;
const curDate = new Date();
const preDate = new Date(curDate.getTime());
const nextDate = new Date(curDate.getTime());
const dateStartTime = authUtil.getStartDateTime();
const drawerWidth = 500;
const formProp = {
  labelCol: { span: 6 },
  wrapperCol: { span: 18 },
};
@connect(({ global, loading, bugstatistics, authority }) => ({
  tableData: bugstatistics.tableData,
  IssueChannelList: bugstatistics.IssueChannelList,
  SalespersonList: bugstatistics.SalespersonList,
  ManufactureList: bugstatistics.ManufactureList,
  searchForm: bugstatistics.searchForm,
  permissionsList: authority.permissionsList,
  tableLoading: loading.effects['bugstatistics/getCensusBugMsg'],
  watermarkConfig: global.watermarkConfig,
}))
class BugStatistics extends PureComponent {
  state = {
    selectedRows: [],
    shieHideBatchDel: false,
    params: {},
    pageRequest: {
      pageNum: 1,
      pageSize: 10,
    },
    drawerStatus: {
      visible: false,
      type: 'add',
    },
    resultDate: [],
    loading: true,
    activeRecord: {},
    inputConfig: [
      {
        type: 'select',
        placeholder: '请选择城市',
        name: 'cityCode',
        label: '城市',
        nameFiled: 'cityName',
        valueFiled: 'cityCode',
        selectProps: {
          showSearch: true,
          allowClear: true,
        }
      },
      {
        type: 'select',
        placeholder: '请选择绑卡类型',
        optionData: [{ value: '0', name: '社保卡' }, { value: '1', name: '公积金卡' }],
        name: 'type',
        label: '绑卡类型',
      },
      {
        type: 'datePicker',
        name: 'createDate',
        label: '时间',
        format: 'YYYY-MM-DD',
      }
    ],
  };
  constructor(props) {
    super(props);
    this.$drawerForm = React.createRef();
    const { pageRequest, params } = this.state;
    this.getSelectList().then(res => {
      this.getQueryList(params, pageRequest);
    })
  }

  // 条件筛选
  /**
   * @description 条件筛选 [搜索]
   * @author zhe
   * @date 2020-04-13
   * @param {*} formData
   * @param {*} reaclData
   * @param {*} isClear
   * @memberof
   */
  actionSearch = (formData, reaclData, isClear) => {
    const params = formData;
    const pageRequest = { pageNum: 1, pageSize: 10 };
    this.setState({
      params: params,
    });
    this.getQueryList(params, pageRequest);
  };

  /**
   * @description 请求列表数据
   * @author zhe
   * @date 2020-04-13
   * @param {*} params
   * @param {*} pageRequest
   * @memberof
   */
  getQueryList = (params, pageRequest) => {
    const type = 'bugstatistics/getCensusBugMsg';
    const param = Object.assign(pageRequest, params);
    const { dispatch } = this.props;
    dispatch({
      type,
      payload: param,
    });
  };
  /**
   * @description 请求事件类型下拉列表数据
   * @author zhe
   * @date 2020-04-14
   * @memberof
   */
  getSelectList = async () => {
    const { inputConfig } = this.state;
    const dataObj = await getAllCity();
    if (dataObj && dataObj.code === '000000') {
      if (dataObj.data !== null) {
        inputConfig[0].optionData = dataObj.data;
        this.setState({ inputConfig: inputConfig });
        return Promise.resolve(dataObj.data);
      }
    }
    return Promise.reject();
  };
  tableCol = () => {
    const OptionNode = ({ record }) => (
      <div className={styles.tableButtonGroup}>
        <Button
          type="link"
          style={{ marginRight: '20px' }}
          onClick={() => {
            this.changeDrawerStatus(true, 'edit', record);
          }}
        >
          编辑
        </Button>
        <Button
          type="link"
          style={{ marginRight: '20px' }}
          onClick={() => {
            this.changeDrawerStatus(true, 'edit', record);
          }}
        >
          推送
        </Button>
        <Popconfirm placement="top" title="删除" onConfirm={() => this.onHandleDelete(record)} okText="确定" cancelText="取消">
          <Button type="link">删除 </Button>
        </Popconfirm>
      </div>
    );
    return [
      {
        title: '城市',
        dataIndex: 'cityName',
        width: '10%',
      },
      {
        title: '绑卡类型',
        dataIndex: 'gradType',
        render: text => { return text == 1 ? '公积金卡' : '社保卡' },
        width: '10%',
      },
      {
        title: '解析失败数量',
        dataIndex: 'count',
        width: '8%',
      },
      {
        title: '创建时间',
        dataIndex: 'createDate',
        width: '8%',
      }
    ];
  };

  render() {
    const { tableCol, handleSelectRows } = this;
    const { selectedRows, inputConfig } = this.state;
    const { tableLoading, watermarkConfig, tableData } = this.props;
    const { list = [], pagination = {} } = tableData;
    return (
      <div>
        <PageHeaderWrapper title="" className="hasContent">
          <div style={{ background: '#fff', padding: '20px 0px 0px 24px', marginBottom: '10px' }}>
            <SearchForm
              defaultInput={inputConfig.slice(0, 3)}
              moreInput={inputConfig.slice(3)}
              gutter={{ md: 10 }}
              useCol={{ sm: 24, md: 12, xl: 8, xxl: 8 }}
              onSearch={this.actionSearch}
            ></SearchForm>
          </div>
          <Card bordered={false}>
            <StandardTable
              isWatermark
              watermark={{ ...watermarkConfig }}
              dataSource={list}
              // showSelect
              selectedRows={selectedRows}
              pagination={{ ...pagination, ...pageInfo }}
              columns={tableCol()}
              loading={tableLoading}
              rowKey={(record, index) => index}
              // onSelectRow={this.handleSelectRows}
              onChange={($pagination, filtersArg, sorter) => {
                this.handleStandardTableChange($pagination, this.state.params, sorter, 'bugstatistics/getCensusBugMsg');
              }}
            ></StandardTable>
          </Card>
        </PageHeaderWrapper>
      </div>
    );
  }
}

export default BugStatistics;
